package course

import (
	"net/http"

	"fmt"

	"awfan.cn/utils"
	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

func remove(format, id string, w http.ResponseWriter, db *mgo.Database) {
	if id == "" {
		utils.WriteError(format, 404, "#id is empty", w)
		return
	}

	if !bson.IsObjectIdHex(id) {
		utils.WriteError(format, 404, fmt.Sprintf("#id is wrong format: '%v'", id), w)
		return
	}

	c := db.C(utils.PkgName(COURSE_XML{}))

	err := c.RemoveId(bson.ObjectIdHex(id))

	if err != nil {
		utils.WriteError(format, 404, err.Error(), w)
		return
	}

	utils.WriteData(format, make(map[string]interface{}), w)
}
